<style lang="scss" scoped>
.class-score-list .item{
    width:30%;
    border-top: 7px solid $error-color;
    .progress{
        width: 140px;
    }
}
</style>
<template>
    <div class="my_lesson">
        <Table :columns="columns" class="diy_table" :data="list">
            <template slot-scope="{ row }" slot="handle">
                <Button size='small' class='mr-1' @click="currentLessonId=row.id;examStateShow=true">交卷情况</Button>
                <Button size='small' class='mr-1' @click="currentLessonId=row.id;scoreStateShow=true">得分情况</Button>
                <Button size='small' class='mr-1' @click="$router.push({path:'/t/teach_exam',query:{lid:row.id}})">讲解</Button>
                <Button size='small' class='mr-1' @click="handle_copy(row)">复制</Button>
                <Button size='small' class="mr-1" @click="$router.push({path:'/t/edit_lesson',query:{lid:row.id}})">编辑</Button>
                <!-- <Button size='small' ghost type="error" @click="handle_del(row)">删除</Button> -->
            </template>
        </Table>
        <div class="clearfix mt-2">
            <Page :current.sync="filters.page" :page-size="filters.list_rows" :total="total_page" show-sizer class="float-right" show-total @on-change="getList_page"/>
        </div>

        <Modal v-model="examStateShow" title="交卷情况"  class-name="diy-modal" width="800">
            <exam-state v-if="examStateShow" :lid="currentLessonId" />
        </Modal>

        <Modal v-model="scoreStateShow" title="得分情况"  class-name="diy-modal" width="800" scrollable>
            <score-state v-if="scoreStateShow" :lid="currentLessonId"/>
        </Modal>
    </div>
</template>

<script>
import pageMixin from "@/common/pageMixin"
import examState from "@/components/examState"
import scoreState from "@/components/scoreState"
import {lessons,copy_lesson_and_questions,teacher_list} from "@/common/tapi"
export default {
    mixins:[pageMixin],
    data(){
        return {
            currentLessonId:'',
            scoreStateShow:false,
            examStateShow:false,
            columns:[
                {
                    title:'课堂编号',
                    key:'id'
                },
                {
                    title: '主题',
                    key: 'title'
                },
                {
                    title: '题目总数',
                    key: 'question_num'
                },
                {
                    title: '平均分',
                    key:'average_score'
                },
                {
                    title: '授课班级',
                    key:'class_num'
                },
                {
                    title: '操作',
                    width:430,
                    slot: 'handle',
                    align: 'center'
                }
            ],
            list:[],
            teacherList:[]
        }
    },
    methods:{
        // handle_del(row){
        //     this.$Modal.confirm({
        //         title: '提示',
        //         content: `确认删除 ${row.title} 吗？`,
        //         onOk: () => {

        //         }
        //     });
        // },
        getList(){
            lessons(this.filters)
            .then(res=>{
                if(res){
                    this.list=res.data.list
                    this.total_page=res.data.pageinfo.total
                }
            })
        },
        handle_copy(row){
            let new_tid=''
            this.$Modal.confirm({
                title:'复制课堂',
                render: (h) => {
                    const option=this.teacherList.map(el=>h('i-option',{props:{value:el.id}},el.name))
                    return h('div',{class:'mt-1'},[
                        h('p',{class:'mb-1'},'课程主题：'+row.title),
                        h('span',{class:'mr-1'},'接收老师'),
                        h('i-select',{
                            class:'w-200',
                            on:{
                                input:val=>{
                                    new_tid=val
                                }
                            }
                        },option),
                        h('p',{class:'mt-2 color-999 font-12'},'接收人将获得该课堂的完整课件！')
                    ])
                },
                onOk:()=>{
                    copy_lesson_and_questions({lid:row.id,new_tid})
                    .then(res=>{
                        if(res){
                            this.$Notice.success({
                                title: '成功',
                                desc: '复制成功'
                            });
                        }
                    })
                }
            })
        }
    },
    components:{
        examState,
        scoreState
    },
    created(){
        this.getList_page()
        teacher_list({list_rows:99999,page:1})
        .then(res=>{
            if(res){
                const tid=+localStorage.getItem('tid')
                this.teacherList=res.data.list.filter(el=>el.id!==tid)
            }
        })
    }
}
</script>
